#!/usr/bin/env python
import glob
import sys

def hex2rom(filename):
	f=open(filename,'r')
	fout = open(filename[:-4]+'.rom','w')
	result = list()
	
	for hexline in f.readlines():
		hexline = hexline.strip()	#delete \n
		if int(hexline[7:9],16) != 0:
			continue
		size = 2*int(hexline[1:3],16)	#16 means hexline[1:3] is a hex data, and show in deceimal
		address = '0000' + hexline[3:7]
		data = hexline[9:9+size]
		fout.write("@"+address+'\n')
		i = 0
		for x in data:
			if (i%2)==0:	#even
				fout.write(x)
				i+=1
			else:
				fout.write(x+' ')
				i+=1

		fout.write('\n')
	fout.close()
	return
	
filename = sys.argv[1] 
hex2rom(filename)
